﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Cryptography;

namespace Service.ZSJL.Com.Security
{
    public class Md5Encrypt : IEncrypt
    {

        #region IEncrypt Members

        public string EnCode(string source)
        {
            return UserMd5(source);
        }

        /// <summary>
        /// MD5是不可逆算法，不实现解密方法
        /// </summary>
        /// <param name="source"></param>
        /// <returns></returns>
        public string DeCode(string source)
        {
            throw new NotImplementedException();
        }

        /// <summary>
        /// MD5 16位加密 加密后密码为小写
        /// </summary>
        /// <param name="ConvertString"></param>
        /// <returns></returns>
        public string GetMd5Str(string ConvertString)
        {
            MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
            string t2 = BitConverter.ToString(md5.ComputeHash(UTF8Encoding.Default.GetBytes(ConvertString)), 4, 8);
            t2 = t2.Replace("-", "");

            t2 = t2.ToLower();

            return t2;
        }


        /// <summary>
        /// MD5　32位加密
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public string UserMd5(string str)
        {
            MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
            string t2 = BitConverter.ToString(md5.ComputeHash(UTF8Encoding.Default.GetBytes(str)));
            t2 = t2.Replace("-", "");

            return t2;
        }
        #endregion

        #region IEncrypt Members


        public string EnCode(string pToEncrypt, string sKey)
        {
            throw new NotImplementedException();
        }

        public string DeCode(string pToEncrypt, string sKey)
        {
            throw new NotImplementedException();
        }

        #endregion
    }
}
